Bash
CLI
tool
Bash is a command line tool and language.
Files
List files
- Number of files in a provided directory
-
ls [myDirectory] | wc -l
Manipulate Files
- Remove directory tree with all its contents
-
rm -rf [myDirectory]
File Permissions
- Show access permissions of file in directory
-
ls -l [myDirectory] - Change permissions of file
-
Explanation
chmod u=rwx,g=rwx,o=rwx [myFile]
Control structures
- Use commandline arguments
-
The
while getopts :c:t flag do case "${flag}" in c) config=${OPTARG} python3 file_to_be_called.py -c $config ;; t) python3 file_to_be_called.py -t ;; :) echo "No arguments passed" exit 1 ;; ?) echo "Please call the script like this: bash_script.sh [-c config_file]" exit 1 ;; esac done:before the flag-characterclets you handle errors yourself (e.g. no arguments passed and wrong arguments passed). The:after the flag-charactercindicates that a value is required after the flag.
Processes
- List running processes
-
htop
| Commands | |
|---|---|
| Help | hh |
| Kill process | k |
| Order processes by memory consumption | Shift-MShift-M |
| Filter processes by user | UU |
| Display files used by the selected process | LL |
| Display user threads | Shift-HShift-H |
- Kill process
-
kill -9 [process-PID] - Info on resource usage & processes on NVidia graphic cards
-
nvidia-smi